#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main()
{
    string line;
    string words[] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
    string* numbers = new string[3];
    int c = 0;
    while(c < 3) 
    {
        cin >> numbers[c];
        c++;
    }
    bool flag = false;
    int st = 2, number = 0;
    for(int i = 0, k = 0; i < c; i++){
        for(k = 0; k <= 9; k++){
            if(numbers[i] == words[k]){
                flag = true;
                break;
            }
        }
        if(flag == false){
            cout<<"Wrong input";
            return 0;
        }
        flag = false;
        number += k * pow(10, st);
        st--;
    }
    int mr = number;
    int* a = new int[1001];
    for (int i = 0; i < 1001; i++) a[i] = i;
    for (int p = 2; p < 1001; p++){
        if (a[p] != 0){
            if(abs(number - a[p]) < mr) mr = number - a[p];
            else{
                cout<<number - mr;
                return 0;
            }
            for (int j = p * p; j < 1001; j += p) a[j] = 0;
        }
    }
    return 0;
}
